package com.simple.simple_view.utils;

import com.alibaba.fastjson.JSON;
import com.simple.simple_view.domain.ResponseResult;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 *@description:
 *@author: hisen
 *@Time: 2023/10/28  20:58
 */
@Slf4j
public class WebUtil
{
    /**
     * 将字符串渲染到客户端
     *
     * @param response 渲染对象
     * @param result 待渲染串
     * @return null
     */
    public static void renderString(HttpServletResponse response, ResponseResult result) {
        try
        {
            response.setStatus(result.getCode());
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(JSON.toJSONString(result));
        }
        catch (IOException e)
        {
            log.error(e.getMessage(),e);
        }
    }
}
